package com.wzz.common.calendar.activity;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.hymobile.common.R;
import com.wzz.common.calendar.views.CalendarView;
import com.wzz.common.calendar.views.Cell;

public class CalendarMain extends Activity implements CalendarView.OnCellTouchListener {
  private CalendarView calendarView;
  Handler mHandler = new Handler();
  private TextView showDate;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.calendar_main);
    calendarView = (CalendarView) findViewById(R.id.calendar);
    calendarView.setOnCellTouchListener(this);

    showDate = (TextView) findViewById(R.id.showDate);
    showDate.setText(calendarView.getYear()+"年"+(calendarView.getMonth()+1)+"月");
  }

  public void onTouch(Cell cell) {
    Calendar aa = cell.getDate();
    String bb = new SimpleDateFormat("yyyy-MM-dd").format(aa.getTime());
    Toast.makeText(getApplicationContext(), bb, Toast.LENGTH_SHORT).show();
  }

  public void setDate(View v){
    Calendar cal = Calendar.getInstance();
    cal.set(2011, 6, 25);
    calendarView.gotoDay(cal);
  }
  
  public void setBack(View v){
    Calendar begin =Calendar.getInstance();
    begin.set(2011, 6, 25);
    Calendar end =Calendar.getInstance();
    end.set(2011, 7, 20);
    calendarView.setBackground(begin, end);
  }

  /**
   * @param cell
   * @see com.jh.calendar.view.OnCellTouchListener#onLongTouch(com.jh.calendar.view.Cell)
   */
  @Override
  public void onLongTouch(Cell cell) {
  }

  /**
   * 
   * @see com.jh.calendar.view.CalendarView.OnCellTouchListener#onMonthChange()
   */
  @Override
  public void onMonthChange() {
    showDate.setText(calendarView.getYear()+"年"+(calendarView.getMonth()+1)+"月");
  }
}